﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using cwtrock.model;
using cwtrock.service.impl;

namespace cwtrock.view.sysmng
{
    public partial class BizhongFrm : Form
    {
        private SysCurrencyServiceImpl service = new SysCurrencyServiceImpl() ;
        private List<SysCurrency> list;
        private static BizhongFrm frm=null;


        #region
        public static BizhongFrm getInstance()
        {
            if (frm == null)
            {
                frm = new BizhongFrm();
            }
            return frm;
        }
        #endregion

        public BizhongFrm()
        {
            InitializeComponent();

           
        }

        private void BizhongFrm_Load(object sender, EventArgs e)
        {
            this.bzDataGridView.AutoGenerateColumns = false;
            this.bzDataGridView.AutoSize = false;
            list = service.findAll();
            this.bzDataGridView.DataSource = list;

            DataGridViewColumn column = new DataGridViewTextBoxColumn();
            column.DataPropertyName = "CURRENCY_CODE";
            column.Name = "code";
            column.HeaderText = "代码";
            this.bzDataGridView.Columns.Add(column);

            column = new DataGridViewTextBoxColumn();
            column.DataPropertyName = "CURRENCY_NAME";
            column.Name = "name";
            column.HeaderText = "名称";
            this.bzDataGridView.Columns.Add(column);

            column = new DataGridViewTextBoxColumn();
            column.DataPropertyName = "CURRENCY_RATE";
            column.Name = "rate";
            column.HeaderText = "记账汇率";
            this.bzDataGridView.Columns.Add(column);

            column = new DataGridViewTextBoxColumn();
            column.Visible = false;
            column.DataPropertyName = "CURRENCY_ID";
            column.Name = "id";
            column.HeaderText = "ID";
            this.bzDataGridView.Columns.Add(column);

        }

        private void clsBtn_Click(object sender, EventArgs e)
        {
            this.Hide();
        }


        public void refresh()
        {
            list = service.findAll();
            this.bzDataGridView.DataSource = list;
        }

        private void addBtn_Click(object sender, EventArgs e)
        {
            bizhongAddFrm addFrm = new bizhongAddFrm(this,0);
            addFrm.Show();
        }

        private void delBtn_Click(object sender, EventArgs e)
        {
            int idx = this.bzDataGridView.SelectedRows[0].Index;
            int id = Convert.ToInt32(this.bzDataGridView.Rows[idx].Cells[3].Value.ToString());
            service.delete(id);
            refresh();
        }

        private void modBtn_Click(object sender, EventArgs e)
        {
            int idx = this.bzDataGridView.SelectedRows[0].Index;
            int id = Convert.ToInt32(this.bzDataGridView.Rows[idx].Cells[3].Value.ToString());
            bizhongAddFrm addFrm = new bizhongAddFrm(this, id);
            addFrm.Show();
        }

    }
}
